// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only

@use '../mixins';
@use '../variables';

.MediaEditor {
  background: variables.$color-gray-95;
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  inset-inline-start: 0;
  top: 0;
  position: absolute;
  user-select: none;
  -webkit-app-region: no-drag;

  z-index: variables.$z-index-popup-overlay;

  &__container {
    display: flex;
    flex: 1;
    padding-block: 64px;
    padding-inline: 64px;
    padding-bottom: 0;
    overflow: hidden;
  }

  &__media {
    align-items: center;
    display: flex;
    height: 100%;
    justify-content: center;
    position: relative;
    width: 100%;

    &--canvas {
      border-radius: 12px;
      transition: border-radius 200ms ease-out;

      &--cropping {
        border-radius: 0;
      }
    }
  }

  &__control {
    @include mixins.button-reset;
    & {
      align-items: center;
      border-radius: 20px;
      display: inline-flex;
      height: 32px;
      justify-content: center;
      margin-block: 0;
      margin-inline: 20px;
      opacity: 1;
      width: 32px;
    }

    &::after {
      content: ' ';
      height: 20px;
      width: 20px;
    }

    &--crop::after {
      @include mixins.color-svg(
        '../images/icons/v3/crop/crop-rotate.svg',
        variables.$color-white
      );
    }

    &--pen::after {
      @include mixins.color-svg(
        '../images/icons/v2/draw-24.svg',
        variables.$color-white
      );
    }

    &--redo {
      &::after {
        @include mixins.color-svg(
          '../images/icons/v3/redo/redo.svg',
          variables.$color-white
        );
      }
      &:disabled::after {
        @include mixins.color-svg(
          '../images/icons/v3/redo/redo.svg',
          variables.$color-gray-45
        );
      }
    }

    &--sticker.module-sticker-button__button::after {
      @include mixins.color-svg(
        '../images/icons/v3/sticker/sticker-smiley.svg',
        variables.$color-white
      );
    }

    &--text::after {
      @include mixins.color-svg(
        '../images/icons/v2/text-24.svg',
        variables.$color-white
      );
    }

    &--undo {
      &::after {
        @include mixins.color-svg(
          '../images/icons/v3/undo/undo.svg',
          variables.$color-white
        );
      }
      &:disabled::after {
        @include mixins.color-svg(
          '../images/icons/v3/undo/undo.svg',
          variables.$color-gray-45
        );
      }
    }

    &--selected {
      background-color: variables.$color-white;

      &::after {
        background-color: variables.$color-black;
      }
    }

    &:hover {
      background-color: variables.$color-gray-80;

      &::after {
        background-color: variables.$color-white;
      }
    }
  }

  &__tools {
    align-items: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 22px;
    width: 100%;

    &--input {
      margin-inline: 24px;
      width: 400px;
    }

    &--buttons {
      align-items: center;
      display: flex;
      justify-content: center;
      width: 100%;
    }

    &__caption {
      height: 44px;

      &__add-caption-button {
        @include mixins.button-reset;
        & {
          @include mixins.rounded-corners;
          background: variables.$color-gray-90;
          color: variables.$color-gray-15;
          padding-block: 8px;
          padding-inline: 15px;
          border: none;
        }

        & > span {
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 1;
          overflow: hidden;
        }
      }
    }
  }

  &__tools-row-1 {
    display: flex;
    flex-grow: 1;
    flex-wrap: wrap;
    height: 28px;
    justify-content: center;
    margin-bottom: 24px;
    max-width: 596px;
  }

  &__tools-row-2 {
    align-items: center;
    display: flex;
    flex-grow: 1;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 596px;
    min-height: 36px;
  }

  &__toolbar__crop {
    align-items: center;
    color: variables.$color-white;
    display: flex;
    height: 36px;
    justify-content: center;
    padding-block: 14px;
    padding-inline: 12px;
    margin-inline: 16px;

    &__button {
      @include mixins.button-reset;
      & {
        display: flex;
        margin-block: 0;
        margin-inline: 20px;
      }
    }
  }

  &__toolbar {
    align-items: center;
    background-color: variables.$color-gray-90;
    border-radius: 10px;
    color: variables.$color-white;
    display: flex;
    height: 36px;
    justify-content: center;
    padding-block: 14px;
    padding-inline: 12px;
    margin-inline: 16px;
    min-width: 418px;

    &__tool,
    &__tool__button {
      margin-inline-start: 14px;
    }

    &__button {
      @mixin icon($icon) {
        @include mixins.color-svg(
          '../images/icons/#{$icon}',
          variables.$color-white
        );
        & {
          opacity: 1;
          height: 20px;
          width: 20px;
          border-radius: 0;
        }

        &::after {
          display: none;
        }
      }

      @include mixins.button-reset;
      & {
        display: flex;
        margin-block: 0;
        margin-inline: 8px;
        padding: 8px;
      }

      &--draw-pen__button {
        @include icon('v3/brush/brush-pen-compact.svg');
      }
      &--draw-highlighter__button {
        @include icon('v3/brush/brush-highlighter-compact.svg');
      }
      &--width-thin__button {
        @include icon('v3/brush_size/brush_size-thin-compact.svg');
      }
      &--width-regular__button {
        @include icon('v3/brush_size/brush_size-regular-compact.svg');
      }
      &--width-medium__button {
        @include icon('v3/brush_size/brush_size-medium-compact.svg');
      }
      &--width-heavy__button {
        @include icon('v3/brush_size/brush_size-heavy-compact.svg');
      }
      &--text-regular__button {
        @include icon('v3/text/text-square-compact.svg');
      }
      &--text-highlight__button {
        @include icon('v3/text/text-square-fill-compact.svg');
      }
      &--text-outline__button {
        @include icon('v3/text/text-outline-compact.svg');
      }
      &--rotate {
        @include icon('v2/rotate-outline-24.svg');
      }
      &--flip {
        @include icon('v2/flip-outline-24.svg');
      }
      &--crop-locked {
        @include icon('v3/crop/crop-lock.svg');
      }
      &--crop-unlocked {
        @include icon('v3/crop/crop-unlock.svg');
      }
    }
  }

  &__icon {
    &--draw-pen {
      @include mixins.color-svg(
        '../images/icons/v3/brush/brush-pen-compact.svg',
        variables.$color-white
      );
    }

    &--draw-highlighter {
      @include mixins.color-svg(
        '../images/icons/v3/brush/brush-highlighter-compact.svg',
        variables.$color-white
      );
    }

    &--text-regular {
      @include mixins.color-svg(
        '../images/icons/v3/text/text-square-compact.svg',
        variables.$color-white
      );
    }

    &--text-highlight {
      @include mixins.color-svg(
        '../images/icons/v3/text/text-square-fill-compact.svg',
        variables.$color-white
      );
    }

    &--text-outline {
      @include mixins.color-svg(
        '../images/icons/v3/text/text-outline-compact.svg',
        variables.$color-white
      );
    }

    &--width-thin {
      @include mixins.color-svg(
        '../images/icons/v3/brush_size/brush_size-thin-compact.svg',
        variables.$color-white
      );
    }

    &--width-regular {
      @include mixins.color-svg(
        '../images/icons/v3/brush_size/brush_size-regular-compact.svg',
        variables.$color-white
      );
    }

    &--width-medium {
      @include mixins.color-svg(
        '../images/icons/v3/brush_size/brush_size-medium-compact.svg',
        variables.$color-white
      );
    }

    &--width-heavy {
      @include mixins.color-svg(
        '../images/icons/v3/brush_size/brush_size-heavy-compact.svg',
        variables.$color-white
      );
    }
  }

  &__history-buttons {
    inset-inline-start: 24px;
    position: absolute;
    top: 40px;
  }

  &__close {
    @include mixins.button-reset;

    & {
      border-radius: 4px;
      height: 20px;
      position: absolute;
      inset-inline-end: 24px;
      top: 40px;
      width: 20px;
    }

    &::before {
      content: '';
      display: block;
      width: 100%;
      height: 100%;
      @include mixins.color-svg(
        '../images/icons/v3/x/x.svg',
        variables.$color-gray-15
      );
    }

    &:hover,
    &:focus {
      box-shadow: 0 0 0 2px variables.$color-ultramarine;
    }
  }

  &__crop-preset {
    @include mixins.button-reset;
    & {
      color: variables.$color-white;
      height: 28px;
      margin-inline: 12px;
      padding-block: 5px;
      padding-inline: 12px;
    }

    &--selected {
      @include mixins.rounded-corners;
      background: variables.$color-gray-80;
    }
  }
}
